#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include<set>
using namespace std;
class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        set<int> nums3(nums1.begin(), nums1.end());
        set<int> nums4(nums2.begin(), nums2.end());
        vector<int> as;
        set<int>::iterator e = nums3.begin();
        set<int>::iterator s = nums4.begin();
        while (e != nums3.end() && s != nums4.end())
        {
            if (*e < *s)
                e++;
            else if (*e > *s)
                s++;
            else
            {
                as.push_back(*e);
                e++;
                s++;
            }
        }
        return as;
    }
};
int main()
{
    Solution as;
    vector<int> ar = { 145,3,6,57,678,58,5768,76,9857,9,5789 };
    vector<int> aw = { 14,5,25,4365,56,4657,5678,6245,4,1,6,5,3,5,6,78,65 };
    vector<int> aq=as.intersection(ar,aw);
    for (auto e : aq)
    {
        cout << e << " ";
    }
    return 0;
}